/**
* 作者: chenlingzhi
* 日期: 2025-04-12 16:25:25
* 备注: 用户好友信息表
*/
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserBuddyApplyInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserBuddyApplyInfoModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 用户ID
	protected byte isLimlit; // 是否开启限制
	protected int limitLevel; // 限制条件等级
	protected int limitVip; // 限制条件vip
	protected byte limitUnion; // 限制条件联盟 (是否同一联盟)

	public void reset() {
	}

	protected String getKey() {
		return "UserBuddyApplyInfo." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_buddy_apply_info"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	* 根据入库类型更新
	*/
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	* 实时入队列
	*/
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 用户ID
		obj.put("isLimlit", isLimlit); // 是否开启限制
		obj.put("limitLevel", limitLevel); // 限制条件等级
		obj.put("limitVip", limitVip); // 限制条件vip
		obj.put("limitUnion", limitUnion); // 限制条件联盟 (是否同一联盟)
		return obj;
	}

	public PBUserBuddyApplyInfo.Builder takeInitBuilder() {
		PBUserBuddyApplyInfo.Builder sb = PBUserBuddyApplyInfo.newBuilder();
		if (isLimlit != 0) {
			sb.setIsLimlit(isLimlit);
		}
		if (limitLevel != 0) {
			sb.setLimitLevel(limitLevel);
		}
		if (limitVip != 0) {
			sb.setLimitVip(limitVip);
		}
		if (limitUnion != 0) {
			sb.setLimitUnion(limitUnion);
		}
		return sb;
	}

	public PBUserBuddyApplyInfo.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUserBuddyApplyInfo.Builder sb = PBUserBuddyApplyInfo.newBuilder();
		if (isFieldUpdate("isLimlit")) {
			sb.setIsLimlit(isLimlit);
		}
		if (isFieldUpdate("limitLevel")) {
			sb.setLimitLevel(limitLevel);
		}
		if (isFieldUpdate("limitVip")) {
			sb.setLimitVip(limitVip);
		}
		if (isFieldUpdate("limitUnion")) {
			sb.setLimitUnion(limitUnion);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public byte getIsLimlit() {
		return isLimlit;
	}

	public void putIsLimlit(byte isLimlit) {
		if (this.isLimlit != isLimlit) {
			this.isLimlit = isLimlit;
			updateRedisHashField(getKey(), "isLimlit", this.isLimlit);
		}
	}

	public void addIsLimlit(byte value) {
		this.isLimlit += value;
		updateRedisHashField(getKey(), "isLimlit", this.isLimlit);
	}

	public int getLimitLevel() {
		return limitLevel;
	}

	public void putLimitLevel(int limitLevel) {
		if (this.limitLevel != limitLevel) {
			this.limitLevel = limitLevel;
			updateRedisHashField(getKey(), "limitLevel", this.limitLevel);
		}
	}

	public void addLimitLevel(int value) {
		this.limitLevel += value;
		updateRedisHashField(getKey(), "limitLevel", this.limitLevel);
	}

	public int getLimitVip() {
		return limitVip;
	}

	public void putLimitVip(int limitVip) {
		if (this.limitVip != limitVip) {
			this.limitVip = limitVip;
			updateRedisHashField(getKey(), "limitVip", this.limitVip);
		}
	}

	public void addLimitVip(int value) {
		this.limitVip += value;
		updateRedisHashField(getKey(), "limitVip", this.limitVip);
	}

	public byte getLimitUnion() {
		return limitUnion;
	}

	public void putLimitUnion(byte limitUnion) {
		if (this.limitUnion != limitUnion) {
			this.limitUnion = limitUnion;
			updateRedisHashField(getKey(), "limitUnion", this.limitUnion);
		}
	}

	public void addLimitUnion(byte value) {
		this.limitUnion += value;
		updateRedisHashField(getKey(), "limitUnion", this.limitUnion);
	}

}